﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GAM_Web_Designer_Pro.Forms;
using GAM_Web_Designer_Pro.Properties;

namespace GAM_Web_Designer_Pro.Classes {
    class AutoSave {

        private Timer _timer1;
        private Timer _timer2;
        private DocumentForm _form;
        private MainForm _parent;

        public AutoSave( DocumentForm form, ref MainForm parent ) {
            _timer1 = new Timer();
            _timer2 = new Timer();
            _timer1.Interval = int.Parse( Settings.Default.AutoSaveInterval );
            _timer2.Interval = 2000;
            _timer2.Enabled = false;
            _timer1.Enabled = false;
            _timer1.Tick += new EventHandler( this._timer1_Tick );
            _timer2.Tick += new EventHandler( this._tiemr2_Tick );
            _form = form;
            _parent = parent;
        }

        public void Start() {
            _timer1.Enabled = true;
        }

        public void Stop() {
            _timer1.Enabled = false;
            _timer2.Enabled = false;
        }

        public void Restart() {
            _timer1.Enabled = false;
            _timer2.Enabled = false;
            _timer1.Enabled = true;
        }

        private void _timer1_Tick( object sender, EventArgs e ) {
            _form.SaveFile();
            _parent.toolStripStatusLabel.Text = "File Saved";
            _timer2.Enabled = true;
        }

        private void _tiemr2_Tick( object sender, EventArgs e ) {
            _parent.toolStripStatusLabel.Text = "Status";
            _timer2.Enabled = false;
        }

    }
}
